package com.bank.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bank.exception.CommonException;
import com.bank.service.TellerService;


@Controller
public class TellerController extends BaseController {
	
	Logger logger = Logger.getLogger(TellerController.class);
	
	@Autowired
	TellerService tellerService;
	/**
	 * 获取柜员列表
	 * */
	@RequestMapping(value="getTellerList.do", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object>  getTellerList(@RequestBody Map<String,Object> params){
		
		List<Object> value = tellerService.getTellerList(params);
		this.setMapListValue("data", value);
		return this.returnMap();
	}
	
	/**
	 *  系统登录
	 * @param params
	 * @param request
	 * @return
	 * @throws CommonException
	 */
	@RequestMapping(value="doLogin.do",method=RequestMethod.POST)
	public  @ResponseBody Map<String, Object> login(@RequestBody Map<String,Object> params, HttpServletRequest request) throws CommonException {
		String tellerNumber = (String)params.get("teller_number");
		String tellerPassword = (String)params.get("teller_password");
		tellerService.login(tellerNumber, tellerPassword, request);
		return this.setAndGetSuccess();
	}
		
	/**
	 * 系统退出
	 * @param request
	 * @return
	 */
	@RequestMapping(value="logout.do")
	public String logout(HttpServletRequest request){
		return tellerService.logout(request);
	}	
	
	/**
	 * 更新柜员信息
	 * @param params
	 * @return
	 * @throws CommonException
	 */
	@RequestMapping(value="updateTeller.do", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object>  updateTeller(@RequestBody Map<String,Object> params) throws CommonException{
		tellerService.updateTellerInfo(params);
		this.setAndGetSuccess();
		return this.returnMap();
	}
	
	/**
	 * 增加柜员
	 * @param params
	 * @return
	 * @throws CommonException
	 */
	@RequestMapping(value="addTeller.do", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object>  addTeller(@RequestBody Map<String,Object> params) throws CommonException{
		tellerService.addTeller(params);
		this.setAndGetSuccess();
		return this.returnMap();
	}
		

}
